package com.example.springbott.service;

import com.example.springbott.bean.MarketLog;
import com.example.springbott.bean.MarketLogExample;
import com.example.springbott.bean.common.CommonData;
import com.example.springbott.bean.common.PageInfoBase;
import com.example.springbott.mapper.MarketLogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AdminLogServiceImpl implements AdminLogService {
    @Autowired
    MarketLogMapper marketLogMapper;

    @Override
    public CommonData adminLogList(PageInfoBase pageInfoBase, String name) {
        PageHelper.startPage(pageInfoBase.getPage(), pageInfoBase.getLimit());
        MarketLogExample marketLogExample = new MarketLogExample();
        marketLogExample.setOrderByClause(pageInfoBase.getSort() + " " + pageInfoBase.getOrder());
        MarketLogExample.Criteria criteria = marketLogExample.createCriteria();
        if (name != null) {
            criteria.andAdminEqualTo(name);
        }
        criteria.andDeletedEqualTo(false);
        List<MarketLog> marketLogs = marketLogMapper.selectByExample(marketLogExample);

        PageInfo<MarketLog> marketLogPageInfo = new PageInfo<>(marketLogs);
        return CommonData.data(marketLogPageInfo);
    }
}
